/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Connection.Connect;
import Connection.DataAccess;
import Model.NhanVien;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author My PC
 */
public class NhanVienController {
    public static boolean ThemNV(NhanVien nv)
    {
        try 
        {
            
           String sql = "INSERT INTO tblNhanVien (MA_NHANVIEN,"
            + " TEN_NHANVIEN,GIOITINH,NGAYSINH,"
            + "DIACHI,DIENTHOAI,SOCMND,EMAIL,CHUCVU,NGAYLAMVIEC,"
            + "USERNAME,PASSWORD) "
                   + "values (N'"+nv.getMaNhanvien()+"', N'"+nv.getTenNhanvien()+"',"
                   + "N'"+ nv.getGioitinh()+"','"+nv.getNgaysinh()+"',N'"+nv.getDiachi()+"',"
                   + "N'"+ nv.getDienthoai()+"', N'"+nv.getSocmnd()+"',"
                   + " N'"+ nv.getEmail()+"',N'"+ nv.getChucvu()+"','"+nv.getNgaylamviec()+"' ,"
                   + "N'"+ nv.getUsername()+"',N'"+ nv.getPassword()+"')";
           //System.out.println("ngày sinh là :" +nv.getNgaysinh());
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean XoaNV(NhanVien nv)
    {
        try 
        {
            
           String sql = String.format("delete from tblNhanVien where MA_NHANVIEN =N'%s'",nv.getMaNhanvien());
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
     public static boolean SuaNV(NhanVien nv)
    {
        try 
        {
            
           String sql ="UPDATE tblNhanVien SET "
            + " TEN_NHANVIEN = N'"+nv.getTenNhanvien()+"',GIOITINH = N'"+nv.getGioitinh()+"',"
            + " NGAYSINH = '"+nv.getNgaysinh()+"',"
            + "DIACHI = N'"+nv.getDiachi()+"',DIENTHOAI = N'"+nv.getDienthoai()+"',"
            + "SOCMND = N'"+nv.getSocmnd()+"',EMAIL = N'"+nv.getEmail()+"',"
            + "CHUCVU = N'"+nv.getChucvu()+"',NGAYLAMVIEC = '"+nv.getNgaylamviec()+"',"
            + "USERNAME = N'"+nv.getUsername()+"',PASSWORD = N'"+nv.getPassword()+"'"
            + "WHERE MA_NHANVIEN= N'"+nv.getMaNhanvien()+"'";
           DataAccess da=new DataAccess();
           da.executeUpdate(sql);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
    
}
